package com.spring.controller;

import com.github.pagehelper.PageHelper;
import com.spring.common.api.CommonResult;
import com.spring.config.interceptor.PassToken;
import com.spring.pojo.Student;
import com.spring.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
public class StudentController {
    @Autowired
    private StudentService service;

    @PassToken
    @GetMapping("student/list")
    public CommonResult<List<Student>> getList() {
//        HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes())
//                .getRequest();
//        String token = request.getHeader("token");
//        System.out.println(token);
        PageHelper.startPage(1, 10);
        List<Student> students = service.selectByExample(null);
        CommonResult<List<Student>> success = CommonResult.success(students);
        return success;
    }
}
